class SyncCallContext : public RefObject {
public:
	inline SyncCallContext() : m_poSyncCallResponse(NULL) {}

	inline virtual ~SyncCallContext() {
		releaseAndClear(m_poSyncCallResponse);
	}

	inline INetworkCommand* getSyncCallResponse() const {
		return m_poSyncCallResponse;
	}

	inline void setSyncCallResponse(INetworkCommand* poSyncCallResponse) {
		setNewRefObject(m_poSyncCallResponse, poSyncCallResponse);
	}

	inline boost::mutex& getSyncCallLock() {
		return m_mxSyncCall;
	}

	inline boost::condition& getSyncCallEvent() {
		return m_evSyncCall;
	}

private:
	INetworkCommand* m_poSyncCallResponse;
	boost::mutex m_mxSyncCall;
	boost::condition m_evSyncCall;
};

class AsyncCallQueueItem {
	public:
		inline AsyncCallQueueItem() :
			m_poRequest(NULL),
			m_poHandler(NULL),
			m_poUserObject(NULL),
			m_poSyncCallContext(NULL) {}

		inline AsyncCallQueueItem (
				INetworkCommand* poRequest,
				ICommandProcessorHandler* poHandler,
				RefObject* poUserObject,
				SyncCallContext* poSyncCallContext ) :
					m_poRequest(poRequest),
					m_poHandler(poHandler),
					m_poUserObject(poUserObject),
					m_poSyncCallContext(poSyncCallContext) {
			if(m_poRequest)
				m_poRequest->addRef();
			if(m_poHandler)
				m_poHandler->addRef();
			if(m_poUserObject)
				m_poUserObject->addRef();
			if(m_poSyncCallContext)
				m_poSyncCallContext->addRef();
		}

		inline AsyncCallQueueItem ( const AsyncCallQueueItem& oSrc ) {
			m_poRequest = oSrc.m_poRequest;
			m_poHandler = oSrc.m_poHandler;
			m_poUserObject = oSrc.m_poUserObject;
			m_poSyncCallContext = oSrc.m_poSyncCallContext;

			if(m_poRequest)
				m_poRequest->addRef();
			if(m_poHandler)
				m_poHandler->addRef();
			if(m_poUserObject)
				m_poUserObject->addRef();
			if(m_poSyncCallContext)
				m_poSyncCallContext->addRef();
		}

		inline void operator = ( const AsyncCallQueueItem& oSrc ) {
			if(this == &oSrc) {
				return;
			}
			releaseAndClear(m_poRequest);
			releaseAndClear(m_poHandler);
			releaseAndClear(m_poUserObject);
			releaseAndClear(m_poSyncCallContext);

			m_poRequest = oSrc.m_poRequest;
			m_poHandler = oSrc.m_poHandler;
			m_poUserObject = oSrc.m_poUserObject;
			m_poSyncCallContext = oSrc.m_poSyncCallContext;

			if(m_poRequest)
				m_poRequest->addRef();
			if(m_poUserObject)
				m_poUserObject->addRef();
			if(m_poHandler)
				m_poHandler->addRef();
			if(m_poSyncCallContext)
				m_poSyncCallContext->addRef();
		}


		inline ~AsyncCallQueueItem() {
			releaseAndClear(m_poRequest);
			releaseAndClear(m_poHandler);
			releaseAndClear(m_poUserObject);
			releaseAndClear(m_poSyncCallContext);
		}

		inline INetworkCommand* getRequest() const {
			return m_poRequest;
		}

		inline ICommandProcessorHandler* getCommandProcessorHandler() const {
			return m_poHandler;
		}

		inline RefObject* getUserRefObject() const {
			return m_poUserObject;
		}

		inline SyncCallContext* getSyncCallContext() const {
			return m_poSyncCallContext;
		}

	private:
		INetworkCommand* m_poRequest;
		ICommandProcessorHandler* m_poHandler;
		RefObject* m_poUserObject;
		SyncCallContext* m_poSyncCallContext;
};


